package edu.neepu;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Main {

    public void startSpider() {
        //get start time
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
        Date startDate = new Date();
        String startTime = format.format(startDate);
        System.out.println("开始爬取 现在时间：" + startTime);

        //start the spider
        BookCount bc = new BookCount();
        try {
            bc.CountBooks();
        } catch (IOException e) {
            e.printStackTrace();
        }

        DownloadPool.getPool().waitUntilStop();

        //get end time
        Date endDate = new Date();
        String endTime = format.format(endDate);
        System.out.println("结束爬取 现在时间：" + endTime);

        //calculate delta time
        SimpleDateFormat format2 = new SimpleDateFormat("HH:mm:ss");
        format2.setTimeZone(TimeZone.getTimeZone("UTC"));
        long delta = endDate.getTime() - startDate.getTime();
        String deltaStr = format2.format(delta);
        System.out.println("共用时" + deltaStr);

    }

    public static void main(String[] args) {
        Main m = new Main();
        m.startSpider();
    }

}
